package com.gwsdk.paysdk.http.process;

import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;

import com.gwsdk.paysdk.config.GWConstant;
import com.gwsdk.paysdk.http.RequestParamUtil;
import com.gwsdk.paysdk.http.request.CodeRequest;
import com.gwsdk.paysdk.utils.GWLog;
import com.lidroid.xutils.http.RequestParams;

import org.apache.http.entity.StringEntity;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

public class CodeProcess {

    private static final String TAG = "CodeProcess";
    private Context context;
    private String phone;
    private int reg;

    public CodeProcess(Context context) {
        this.context = context;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setReg(int reg) {
        this.reg = reg;
    }

    public void post(Handler handler){

        if (null == handler) {
            GWLog.e(TAG, "fun#post handler is null");
            return;
        }
        Map<String, String> map = new HashMap<String, String>();
        map.put("phone", phone);//表示android发送的请求，固定值1
        map.put("reg", "5");
        RequestParams params = new RequestParams();
        String param = RequestParamUtil.getRequestParamString(map);
        if (TextUtils.isEmpty(param)) {
            GWLog.e(TAG, "fun#post param is null");
            return;
        }
        try {
            params.setBodyEntity(new StringEntity(param.toString()));
        } catch (UnsupportedEncodingException e) {
            params = null;
            GWLog.e(TAG, "fun#post UnsupportedEncodingException:" + e);
        }
        if (null != params) {
            CodeRequest loginRequest = new CodeRequest(handler);
            loginRequest.post(GWConstant.getInstance().getVerifyPhoneCodeUrl(), params,context);
        } else {
            GWLog.e(TAG, "fun#post RequestParams is null");
        }
    }



}
